/////////////////////////////////////////////////////////////////////////////
// Original code from libhdfs3. Copyright (c) 2013 - 2014, Pivotal Inc.
// All rights reserved. Author: Zhanwei Wang
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//



#pragma once

#include <string>

namespace Hdfs {
    namespace Internal {
        class WritableUtils {
        public:
            WritableUtils(char *b, size_t l);

            int32_t ReadInt32();

            int64_t ReadInt64();

            void ReadRaw(char *buf, size_t size);

            std::string ReadText();

            int readByte();

            size_t WriteInt32(int32_t value);

            size_t WriteInt64(int64_t value);

            size_t WriteRaw(const char *buf, size_t size);

            size_t WriteText(const std::string &str);

        private:
            int decodeWritableUtilsSize(int value);

            void writeByte(int val);

            bool isNegativeWritableUtils(int value);

            int32_t ReadBigEndian32();

        private:
            char *buffer;
            size_t len;
            size_t current;
        };
    }
}
